package com.hzdesk.media.koreabatchmatvector.fragment.fragment_view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.adapter.MyVideoListAdapter;
import com.hzdesk.media.koreabatchmatvector.bean.Memory;
import com.hzdesk.media.koreabatchmatvector.bean.VideoFile;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.config.RxBusUtil;
import com.hzdesk.media.koreabatchmatvector.dao.MemoryDaoUtils;
import com.hzdesk.media.koreabatchmatvector.dao.VideoFileDaoUtils;
import com.hzdesk.media.koreabatchmatvector.dialog.DeleteFileDialog;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_contract.VideoListContract;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_persenter.VideoListPersenter;
import com.hzdesk.media.koreabatchmatvector.inter.OnItemClickListener;
import com.hzdesk.media.koreabatchmatvector.logic.view.DialogActivity;
import com.hzdesk.media.koreabatchmatvector.logic.view.VideoPlayerActivity;
import com.hzdesk.media.koreabatchmatvector.utils.RxBus;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.functions.Consumer;
import me.zhouzhuo.zzhorizontalprogressbar.ZzHorizontalProgressBar;

/**
 * Created by Administrator on 2018/6/22.
 * 杭州席媒科技有限公司  Developers  刘传华  15
 * 佛祖镇楼 bug辟易
 */

public class VideoListFragment extends BaseFragment implements VideoListContract.IVideoListView{
    @BindView(R.id.fragment_my_video_list_iv_back)
    ImageView fragmentMyVideoListIvBack;
    @BindView(R.id.fragment_my_video_list_iv_intent_to_cloud)
    ImageView fragmentMyVideoListIvIntentToCloud;
    @BindView(R.id.fragment_my_video_list_iv_delect_all)
    ImageView fragmentMyVideoListIvDelectAll;
    @BindView(R.id.fragment_my_video_list_iv_sort)
    ImageView fragmentMyVideoListIvSort;
    @BindView(R.id.fragment_my_video_list_progress)
    ZzHorizontalProgressBar fragmentMyVideoListProgress;
    @BindView(R.id.fragment_my_video_list_tv_storage)
    TextView fragmentMyVideoListTvStorage;
    @BindView(R.id.fragment_my_video_listview)
    RecyclerView fragmentMyVideoListview;
    Unbinder unbinder;

    private List<Memory> memoryList;
    private VideoFileDaoUtils videoFileDaoUtils;
    private List<VideoFile> list;
    private MyVideoListAdapter mMyVideoListAdapter;
    private VideoListPersenter mVideoListPersenter = new VideoListPersenter(this);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_video_list, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mVideoListPersenter.initDate(mcontext,fragmentMyVideoListview);
    }
    @OnClick({R.id.fragment_my_video_list_iv_back, R.id.fragment_my_video_list_iv_intent_to_cloud,
            R.id.fragment_my_video_list_iv_delect_all, R.id.fragment_my_video_list_iv_sort})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fragment_my_video_list_iv_back:
                mVideoListPersenter.onClicked(RxBusUtil.SET_FRAGMENT_BACK);
                break;
            case R.id.fragment_my_video_list_iv_intent_to_cloud:
                mVideoListPersenter.onClicked(RxBusUtil.CHANGE_CLOUD_LIST_FRAGMENT);                //  显示云端列表 7
                break;
            case R.id.fragment_my_video_list_iv_delect_all:
                mVideoListPersenter.clearAll();
                break;
            case R.id.fragment_my_video_list_iv_sort:
                mVideoListPersenter.onCliakedSort();
                break;
        }
    }
    @Override
    public void toVideoPlayerPager(String path) {
        Intent intent=new Intent();
        intent.setClass(mcontext, VideoPlayerActivity.class);
        intent.putExtra("vidofile_path",path);
        mcontext.startActivity(intent);
    }

    @Override
    public void sendMessage(int pager) {
        RxBus.getInstance().send(pager);                                            //  显示云端列表 7
//        if(pager == RxBusUtil.CHANGE_CLOUD_LIST_FRAGMENT){
//            Intent intent = new Intent(mcontext, DialogActivity.class);
//            intent.putExtra("Dialog_viewpage_index",pager);
//            mcontext.startActivity(intent);
//        }else{
//            RxBus.getInstance().send(pager);
//        }

    }

    @Override
    public void sendMessageTwo(String msg) {
        RxBus.getInstance().send(msg);
    }

    @Override
    public void setStorageMessage(String msg) {
        fragmentMyVideoListTvStorage.setText(msg);
    }

    @Override
    public void setProgress(int progress) {
        fragmentMyVideoListProgress.setProgress(progress);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
